<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>网站设置</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="{__STATIC__}/layuiAdmin/layui/css/layui.css" rel="stylesheet">
	<link href="{__STATIC__}/layuiAdmin/adminui/dist/css/admin.css" rel="stylesheet">
	<link href="{__STATIC__}/layuiAdmin/style/style.css" rel="stylesheet">
</head>
<body>
<div class="layui-fluid">
	<form class="layui-form" style="padding-bottom: 45px;">
		<div class="layui-card">
			<div class="layui-card-body">
				<div class="layui-tab layui-tab-brief">
					<ul class="layui-tab-title">
						<li class="layui-this">基本设置</li>
						<li>其他设置</li>
					</ul>
					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">
							<div class="layui-form-item">
								<label class="layui-form-label"><span>*</span> 网站地址：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_url" lay-verify="required" placeholder="请输入网站地址" class="layui-input" {eq name="$site.url" value=""}value="http://{:$_SERVER['HTTP_HOST']}"{else}value="{$site.url}"{/eq}>
								</div>
								<div class="layui-form-mid layui-word-aux">如：http://www.aaa.com</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label"><span>*</span> 网站名称：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_title" lay-verify="required" placeholder="请输入网站名称" class="layui-input" value="{$site.title}">
								</div>
								<div class="layui-form-mid layui-word-aux">将显示到前台title中</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">网站Logo：</label>
								<div class="layui-input-inline">
									<input type="text" id="m_pic" name="m_logo" placeholder="请上传Logo" class="layui-input" value="{$site.logo}">
								</div>
								<div class="layui-btn-group">
									<button type="button" class="layui-btn layui-btn-info" id="btn_upload" style="padding-left: 10px;padding-right: 10px;">
										<i class="layui-icon">&#xe681;</i>上传
									</button>
									<button type="button" class="layui-btn layui-btn-info" id="btn_preview" style="padding-left: 10px;padding-right: 10px;">
										<i class="layui-icon">&#xe615;</i>预览
									</button>
								</div>
								<span style="display:none;" id="pic"><img id="yl_pic" src="/upload/pic/{$site.logo}"></span>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">联系人：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_name" placeholder="请输入联系人" class="layui-input" value="{$site.name}">
								</div>
								<div class="layui-form-mid layui-word-aux"></div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">联系电话：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_phone" placeholder="请输入联系电话" class="layui-input" value="{$site.phone}">
								</div>
								<div class="layui-form-mid layui-word-aux">用于用户咨询</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">手机号码：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_tel" placeholder="请输入手机号码" class="layui-input" value="{$site.tel}">
								</div>
								<div class="layui-form-mid layui-word-aux">用于用户咨询及接收短信</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">公众号openid：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_openid" placeholder="请输入公众号openid" class="layui-input" value="{$site.openid}">
								</div>
								<div class="layui-form-mid layui-word-aux">填写管理员的openid，可用于接收订单消息</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">在线咨询QQ：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_qq" placeholder="请输入QQ号码" class="layui-input" value="{$site.qq}">
								</div>
								<div class="layui-form-mid layui-word-aux">用于QQ在线咨询</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">用户名保留字：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_user_reserved_word" placeholder="用户名保留字" class="layui-input" value="{$site.user_reserved_word}">
								</div>
								<div class="layui-form-mid layui-word-aux">这些不能注册，多个请用“,”隔开</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">网站关键词：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_keys" placeholder="请输入关键词" class="layui-input" value="{$site.keywords}">
								</div>
								<div class="layui-form-mid layui-word-aux">将显示到前台meta-keywords中</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">网站描述：</label>
								<div class="layui-input-inline w400">
									<input type="text" name="m_des" placeholder="请输入网站描述" class="layui-input" value="{$site.description}">
								</div>
								<div class="layui-form-mid layui-word-aux">将显示到前台meta-description中</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">热搜词：</label>
								<div class="layui-input-inline w400">
									<input type="text" name="m_hot_key" placeholder="请输入热搜词" class="layui-input" value="{$site.hot_key}">
								</div>
								<div class="layui-form-mid layui-word-aux">不同词用“|”隔开</div>
							</div>
							<div class="layui-form-item" style="display: none;">
								<label class="layui-form-label">版权信息：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_copyright" placeholder="请输入版权信息" class="layui-input" value="{$site.copyright}">
								</div>
								<div class="layui-form-mid layui-word-aux">一般放在网站底部，为空将不显示。</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">公司名称：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_company" placeholder="请输入公司名称" class="layui-input" value="{$site.company}">
								</div>
								<div class="layui-form-mid layui-word-aux"></div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">网站备案号：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_record" placeholder="请输入网站备案号" class="layui-input" value="{$site.record}">
								</div>
								<div class="layui-form-mid layui-word-aux"></div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">手机验证码登录：</label>
								<div class="layui-input-inline w50">
									<input type="checkbox" name="m_code_login" value="1" lay-text="是|否" {eq name="$site.code_login" value="1"}checked{/eq} lay-skin="switch">
								</div>
								<div class="layui-form-mid layui-word-aux">开启后需要配置短信设置</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">第三方登录：</label>
								<div class="layui-input-inline w50">
									<input type="checkbox" name="m_other_login" value="1" lay-text="是|否" {eq name="$site.other_login" value="1"}checked{/eq} lay-skin="switch">
								</div>
								<div class="layui-form-mid layui-word-aux">开启后可支持微信等快捷登录</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">启用PC端：</label>
								<div class="layui-input-inline w50">
									<input type="checkbox" name="m_openpc" value="1" lay-text="是|否" {eq name="$site.open_pc" value="1"}checked{/eq} lay-skin="switch">
								</div>
								<div class="layui-form-mid layui-word-aux">开启后PC打开显示PC模板</div>
							</div>
							<input type="hidden" name="m_template" value="{$site.template}">
						</div>
						<div class="layui-tab-item">
							<div class="layui-form-item">
								<label class="layui-form-label"><span>*</span> AppID：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_app_id" lay-verify="required" placeholder="请输入AppID" class="layui-input" value="{$site.app_id}">
								</div>
								<div class="layui-form-mid layui-word-aux">16位AppID</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label"><span>*</span> AppKey：</label>
								<div class="layui-input-inline">
									<input type="text" name="m_api_key" lay-verify="required" placeholder="请输入ApiKey" class="layui-input" value="{$site.api_key}">
								</div>
								<div class="layui-form-mid layui-word-aux">16位App秘钥</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">腾讯地图Key：</label>
								<div class="layui-input-inline" style="width: 350px;">
									<input type="text" name="m_map_key" placeholder="请输入腾讯地图Key" class="layui-input" value="{$site.map_key}">
								</div>
								<div class="layui-form-mid layui-word-aux"><a href="https://lbs.qq.com/dev/console/application/mine" target="_blank">申请地址</a></div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">Token有效期：</label>
								<div class="layui-input-inline w120">
									<select name="m_token_ttl">
										{for start="1" end="31"}
										<option value="{$i}" {eq name="$site.token_ttl" value="$i"}selected{/eq}>{$i}分钟</option>
										{/for}
									</select>
								</div>
								<div class="layui-form-mid layui-word-aux">access_token有效期</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">刷新Token有效期：</label>
								<div class="layui-input-inline w120">
									<select name="m_refresh_token_ttl">
										{for start="1" end="31"}
										<option value="{$i}" {eq name="$site.refresh_token_ttl" value="$i"}selected{/eq}>{$i}天</option>
										{/for}
									</select>
								</div>
								<div class="layui-form-mid layui-word-aux">这么久无需登录，自动刷新access_token</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">日志有效期：</label>
								<div class="layui-input-inline w120">
									<select name="m_log_days">
										<option value="7" {eq name="$site.log_days" value="7"}selected{/eq}>7天</option>
										<option value="15" {eq name="$site.log_days" value="15"}selected{/eq}>15天</option>
										<option value="30" {eq name="$site.log_days" value="30"}selected{/eq}>30天</option>
										<option value="60" {eq name="$site.log_days" value="60"}selected{/eq}>60天</option>
										<option value="90" {eq name="$site.log_days" value="90"}selected{/eq}>90天</option>
										<option value="0" {eq name="$site.log_days" value="0"}selected{/eq}>不限</option>
									</select>
								</div>
								<div class="layui-form-mid layui-word-aux">后台日志有效期</div>
							</div>
							<input type="hidden" name="m_user_recharge" value="{$site.user_recharge}">
							<input type="hidden" name="m_user_recharge_gift" value="{$site.user_recharge_gift}">
							<div class="layui-form-item">
								<label class="layui-form-label">缓存类型：</label>
								<div class="layui-input-inline w120">
									<select name="m_cache_type" lay-filter="m_cache_type">
										<option value="file" selected>本地文件</option>
									</select>
								</div>
							</div>
							<div id="span_cache_type" style="display: none;">
								<div class="layui-form-item">
									<label class="layui-form-label">Redis地址：</label>
									<div class="layui-input-inline w150">
										<input type="text" name="m_redis_host" placeholder="输入Redis地址" class="layui-input" value="127.0.0.1">
									</div>
									<div class="layui-form-mid layui-word-aux">如：127.0.0.1</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">Redis端口：</label>
									<div class="layui-input-inline w150">
										<input type="text" name="m_redis_port" placeholder="输入Redis端口" class="layui-input" value="6379">
									</div>
									<div class="layui-form-mid layui-word-aux">一般为6379</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">Redis密码：</label>
									<div class="layui-input-inline w150">
										<input type="text" name="m_redis_auth" placeholder="输入Redis密码" class="layui-input" value="">
									</div>
									<div class="layui-form-mid layui-word-aux"></div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="m_footer">
			<button class="layui-btn layui-btn-normal" lay-submit lay-filter="LAY-submit">提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
	</form>
</div>
</body>
</html>
<script src="{__STATIC__}/layuiAdmin/layui/layui.js"></script>
<script>
	layui.config({
		base: '{__STATIC__}/layuiAdmin/' // 静态资源所在路径
	}).use(['index','form','upload'], function(){
		let $ = layui.$;
		let layer = layui.layer;
		let upload = layui.upload;
		let form = layui.form;

		/* 监听select */
		form.on('select(m_cache_type)',function (data) {
			if(data.value == 'file'){
				$("#span_cache_type").hide();
			}
			else {
				$("#span_cache_type").show();
			}
		});

		//上传
		upload.render({
			elem: '#btn_upload'
			,url: "{:url('upload/index')}"
			,data: {dir: 'logo'}
			,accept: 'images'
			,before: function () {
				layer.load();
			}
			,done: function(res){
				layer.closeAll();
				if(res.code == 0) {
					$('#m_pic').val(res.data.file);
					$('#yl_pic').attr('src',res.data.src);
				}
				else {
					layer.msg(res.msg);
				}
			}
			,error: function(){
				layer.closeAll();
				layer.msg('请求异常');
			}
		});
		//预览
		$('#btn_preview').click(function () {
			layer.open({
				type: 1,
				shade: false,
				title: false,
				content: $('#pic')
			});
		});

		/* 监听提交 */
		form.on('submit(LAY-submit)', function(data){
			let field = data.field; //获取提交的字段
			let open_pc = field.hasOwnProperty('m_openpc') ? field.m_openpc : 0;
			let code_login = field.hasOwnProperty('m_code_login') ? field.m_code_login : 0;
			let other_login = field.hasOwnProperty('m_other_login') ? field.m_other_login : 0;
			$.ajax({
				type:"post",
				url:"saveSite.html",
				data: {
					m_url:field.m_url,
					title:field.m_title,
					logo:field.m_logo,
					name:field.m_name,
					phone:field.m_phone,
					tel:field.m_tel,
					qq:field.m_qq,
					openid:field.m_openid,
					template:field.m_template,
					keywords:field.m_keys,
					description:field.m_des,
					hot_key:field.m_hot_key,
					company:field.m_company,
					record:field.m_record,
					copyright:field.m_copyright,
					open_pc:open_pc,
					app_id:field.m_app_id,
					api_key:field.m_api_key,
					map_key:field.m_map_key,
					token_ttl:field.m_token_ttl,
					refresh_token_ttl:field.m_refresh_token_ttl,
					user_reserved_word:field.m_user_reserved_word,
					code_login:code_login,
					other_login:other_login,
					user_recharge:field.m_user_recharge,
					user_recharge_gift:field.m_user_recharge_gift,
					log_days:field.m_log_days,
					cache_type:field.m_cache_type,
					redis_host:field.m_redis_host,
					redis_port:field.m_redis_port,
					redis_auth:field.m_redis_auth
				},
				dataType:"json",
				beforeSend: function () {
					layer.load(1);
				},
				success:function(res){
					layer.closeAll(); //关闭弹层
					if(res.code == 0){
						layer.msg('修改成功', {
							time: 2000
						}, function(){
							location.reload();
						});
					}
					else {
						layer.msg(res.msg);
					}
				}
			});
			return false;
		});
	});
</script>